import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testcase = "dbshop024-删除评价"

#
# 1.登录前台界面，
firefox = openBrowser(url)
DBshopLogin(firefox,userName,password)
# 点击我的订单，已完成订单，
firefox.find_element_by_link_text("我的订单").click()
firefox.find_element_by_xpath('//a[contains(.,"交易完成")]').click()
time.sleep(5)
# 点击尚未评价
firefox.find_element_by_xpath('//a[@class="btn btn-small btn-primary"][1]').click()
time.sleep(5)
# 编写商品评价“下次还是会回购”，点击“点击提交”按钮。
firefox.find_element_by_id("comment_body").send_keys(comment_body)
firefox.find_element_by_xpath('//button[text()="点击提交"]').click()
firefox.close()

# 2.回到后台界面
firefox = openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)

DBshopEnterMenu2(firefox,"商品管理","商品评价")
# 点击“编辑查看”，点击“评价回复”
firefox.find_element_by_link_text("编辑查看").click()
time.sleep(5)
# 轴定位
firefox.find_element_by_xpath('//td[contains(.,"%s")]/following-sibling::td[4]/a[2]'%(comment_body)).click()
time.sleep(5)

try:
    firefox.find_element_by_xpath\
        ('//td[contains(.,"%s")]'%(comment_body)).is_displayed()
    writeLog("%s 测试失败" % testcase)
    getPhoto(firefox)
except:
    writeLog("%s 测试通过" % testcase)
# firefox.quit()